<?php

namespace common\models;

use Yii;
use yii\web\UploadedFile;
/**
 * This is the model class for table "article_image".
 *
 * @property string $id
 * @property integer $article_id
 * @property string $article_image
 */
class ArticleImage extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'article_image';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['article_id', 'article_image'], 'required'],
            [['article_image'],'file','skipOnEmpty' => false, 'extensions' => 'png, jpg'],
            [['article_id'], 'integer'],
            [['article_image'], 'string', 'max' => 60],
        ];
    }

    public function upload()
    {
        if ($this->validate()) {
            $this->imageFile->saveAs('frontend/views/uploads/' . $this->imageFile->baseName . '.' . $this->imageFile->extension);
            return true;
        } else {
            return false;
        }
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => '主键',
            'article_id' => '文章id',
            'article_image' => '图片',
        ];
    }
}
